var _GEWaitResponse = false;
var _GEEventList = new Array();
var _GEResponseList = new Array();
var _GEAskList = new Array();
var _GEDelayAskList = new Array();
var _GEEventing;

function GEEvent(name,parameter){
	this.name=name;
	this.parameter=parameter;
};

function GEDoEvent(){
	_GEEventing = true;
		switch(_GEEventList[0].name){
			case "开始":{
				_GDNowMenu = "";
				GUIShowSkillIcon(_GDNowChess);
				_GEEventList.shift();
				if(_GDNowChess.ai != "")
					AILuncher(_GDNowChess.ai);
				CEEffectsTrigger();
				CSDestoryListener();
				GUIRefrshHPMP(_GDNowChess);
				if(_GEEventList.length == 0){
					_GLState = "等待操作";
					GUIShowNowAction();
				}
				GUIRefrshChess();
				break;
			}
			case "移动":{
				var para = _GEEventList[0].parameter.split(",");
				GAChessMove(para[0],new GDposition(para[1],para[2]),new GDposition(para[3],para[4]));
				_GEEventList.shift();
				break;
			}
			case "攻击":{
				var para = _GEEventList[0].parameter.split(",");
				var tos = new Array();
				_GEEventList.shift();
				tos.push(CFindById(para[1]).position);
				_GEEventList.unshift(new GEEvent("效果",new ChessEffect("Attack",para[0],tos)));
				break;
			}
			case "技能":{
				var para = new Array();
				para = _GEEventList[0].parameter.split(",");
				_GEEventList.shift();
				var chess = CFindById(para[0]);
				if(CSUseMagic(para[0],chess.skill[para[1]].cost)){
					Skill(para[0],new GDposition(para[2], para[3]),chess.skill[para[1]]);
				}
				break;
			}
			case "效果":{
				console.log("执行效果:"+_GEEventList[0].parameter.id);
				CEEffectLuncher(_GEEventList[0].parameter.id,_GEEventList[0].parameter.from,_GEEventList[0].parameter.tos);
				_GEEventList.shift();
				if(_GEEventList.length == 0)
					CSDestoryListener();
				GUIRefrshChess();
				break;
			}
			case "破坏":{
				_GAList.push(new GameAnm("破坏",0,_GEEventList[0].parameter));
				_GEEventList.shift();
				_GLState = "动画运行";
				break;
			}
			case "延迟":{
				_GEEventList.shift();
				GLDelay();
				break;
			}
			case "结束":{
				_GEEventList.shift();
				if(_GDNowChess!=null)
					CEEffectsEnd();
				CSDestoryListener();
				if(_GEEventList.length == 0){
					console.log("回合结束");
					GLEndStep();
				}
				break;
			}
		}
	_GEEventing = false;
};

function GEAskForResponse(){
	if(_GEEventList.length == 0){
		_GLState = "等待操作";
		if(!_GDAttackDone&&_GDNowChess!=null)
			GUIShowNowAction();
		return;
	}
	var response = false;
	if(_GEDelayAskList.length==0){
		for(i in _GDChessList){
			
		}
	}
	if(response){
		_GLState = "等待操作";
	}
	else{
		_GLState = "事件执行";
	}
};